package logic

import (
	"context"

	"good_rpc/internal/svc"
	"good_rpc/pb/good"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteGoodLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteGoodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteGoodLogic {
	return &DeleteGoodLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteGoodLogic) DeleteGood(in *good.IDRequest) (*good.Empty, error) {
	err := l.svcCtx.GoodModel.Delete(l.ctx, in.Id)
	if err != nil {
		l.Logger.Errorf("DeleteGood failed: id=%d, error: %v", in.Id, err)
		return nil, err
	}
	return &good.Empty{}, nil
}
